package day1127_2;

import java.sql.*;

public class D3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cd.jdbc.Driver");//1.
        //2.建立连接
        Connection  conn= DriverManager.getConnection("","root","root");//2.
        //3.发送sql给mysql(预编译)
        PreparedStatement stmt=conn.prepareStatement("select * from stu");
        ResultSet  rs=stmt.executeQuery();//4.执行查询
        while(rs.next()){//5.获取查询结果
            System.out.println(rs.getInt(1));
            System.out.println(rs.getString(2));
        }
        conn.close();//6.关闭链接
    }
}


